<!-- 问卷调查页面 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="../res/css/weui.css" />
    <link rel="stylesheet" href="../res/css/weuix.css" />
    <link rel="stylesheet" href="../res//css/common.css">
    <link rel="stylesheet" href="../res/css/swiper.css">
    <script src="../res/js/zepto.min.js"></script>
    <script src="../res/js/zepto.weui.js"></script>
    <script src="../res/js/common.js?v=1"></script>
    <script src="../res/js/swiper.js"></script>
</head>
<script>
    $(function () {
        $("#btnBack").click(function () {
            goPage("user_physical_examin.htm");
        })
        $('.weui-form-checkbox').change(function(){
            console.log($(this).val());
        })
    })
</script>
<style>
    .invest_contain {
        width: 92%;
        margin-top: 10px;
        margin-left: 4%;
        border-radius: 10px;
        background-color: white;
        overflow: hidden;
    }

    .invest_contain>div {
        width: 80%;
        margin: 30px 10%;
    }
    .choose_item>div {
        width: 80%;
        margin: 30px 0;
    }
    .invest_contain p {
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #353535;
        line-height: 16px;
    }
    .weui-form-checkbox[type="radio"]:checked+label .weui-icon-radio {
        background-color: #1189FF;
        border: 1px solid #1189FF;
    }

</style>
<script>
    window.onload = function () {
        var options = [
            ],
            questions = [
            ],
        page = 0,answers=""
        //体质问卷获取
        var params ={
            "facePictureBase64":localStorage.getItem("facePhoto"),
            "tonguePictureBase64":localStorage.getItem("tonguePhoto")
        }
        console.log(params);
        newAjaxPost("/h5/smart/questionnaire", params, getQuestionnaireOk);
        function getQuestionnaireOk(json){
            if(json.code == 0){
                console.log(json);
                msgInfo(`${json.msg},请重新拍照`)
                setTimeout(()=>{
                    goPage("user_physical_examin.htm");
                },2000)
            }
            else{
                console.log(json);
                options = json.data.options
                questions = json.data.questions
                localStorage.setItem('requestId',json.data.requestId)
                localStorage.setItem('mainCorporeity',json.data.mainCorporeity)
            }
        }
        
        $(capture).hide()

        //这个问卷页面渲染
        function Questionnaire() {
            var optionitem = ''
            options.reduce((pre, item, index) => {
                optionitem += `<div class="weui-form-li">
                    <input class="weui-form-checkbox" name="1" id="${index}" value="${item.con}" type="radio">
                    <label for="${index}"><i class="weui-icon-radio"></i>
                        <div class="weui-form-text">
                            <p>${item.con}</p>
                        </div>
                    </label>
                </div>`
            }, 0)
            $('.choose_item').html(optionitem)
            $('.option_title').html(`${page+1}.${questions[page].con}`)
            $('.page_number').html(`第${page+1}页 共${questions.length}页`)
        }
        
        Questionnaire()

        //点击选择函数
        $(document).on("click", ".weui-form-checkbox", function () {
            console.log($(this).val());
            answers+=`${$(this).val()}|`
            if(page<4){
                page++;
                setTimeout(function(){
                    Questionnaire()
                },500)
            }
            else if(page==4){
                $(capture).show()
            }
        })

        $("#capture").click(function(){         
            localStorage.setItem("answers",answers.substring(0,answers.length-1))
            goPage(`user_conditioning_plan.htm?hrefUrl=conditioning_plan`);
        })
    }
</script>
<body>
    <div class="fixed-top">
        <div class="weui-header weui-btn_primary">
            <div class="weui-header-left"><a id="btnBack" class="icon icon-109 "></a></div>
            <div class="weui-header-title">问卷调查</div>
            <div class="weui-header-right"></div>
        </div>
    </div>

    <div class="invest_contain">
        <div class="option_title"
            style="font-size: 17px;font-family: PingFang SC;font-weight: 500;color: #1189FF;line-height: 18px;"></div>
        <div class="choose_item"></div>
        <div class="page_number"
            style="font-size: 15px;font-family: PingFang SC;font-weight: 500;color: #757575;line-height: 16px;width: 100%;margin: 40px 0 20px 0;text-align: center;">
        </div>
        <a class="weui-btn bg-blue" id="capture"
            style="width: 80%;background-color: #1189FF; margin: 40px 10% 20px 10%;">点击提交,进行分析</a>
    </div>
</body>

</html>